package com.googlecode.FWT.view.pages.activity
{
	import com.googlecode.FWT.core.NotificationNames;
	import com.googlecode.FWT.model.ProjectDataProxy;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;

	/**
	 * Integrates the FreeWrite view component with the PureMVC framework.
	 * 
	 */
	public class FreeWriteMediator extends Mediator
	{
		/**
		 * PureMVC identifier 
		 */
		public static const NAME:String = "FreeWriteMediator";
		
		/**
		 * Constructor. 
		 * @param viewComponent
		 * 
		 */
		public function FreeWriteMediator(viewComponent:FreeWrite)
		{
			super(NAME, viewComponent);
		}
		
		/**
		 * Called once the mediator has been registered. Used to set up the free write activity. 
		 * 
		 */
		override public function onRegister():void
		{
			var proxy:ProjectDataProxy = facade.retrieveProxy(ProjectDataProxy.NAME) as ProjectDataProxy;
			var essayTitle:String = proxy.essayTitle as String;
			
			(viewComponent as FreeWrite).essayTitle = essayTitle;
		}
		/* override public function onRemove():void
		{
			super.onRemove();
			
		} */
		/**
		 * Notify interest in clear button being clicked. 
		 * @return 
		 * 
		 */
		override public function listNotificationInterests():Array
		{
			var list:Array = super.listNotificationInterests();
			list.push(NotificationNames.CLEAR_FW);
			list.push(NotificationNames.PRINT);
			
			return list;
		}
		
		/**
		 * Call the clear method on FreeWrite when the Clear button has been clicked. 
		 * Handles the Print button being clicked.
		 * @param notification
		 * 
		 */
		override public function handleNotification(notification:INotification):void
		{
			switch(notification.getName())
			{
				case NotificationNames.CLEAR_FW:
					(viewComponent as FreeWrite).clear();
					break;
				case NotificationNames.PRINT:
					var freeWriteArea:PrintTextArea = (viewComponent as FreeWrite).freeWriteArea as PrintTextArea; 
					sendNotification(NotificationNames.PRINT_READY, freeWriteArea); 
					break;
			}
			
		}
	}
}